import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
Para incorporar o google drive, utilize o código abaixo
#from google.colab import drive
#drive.mount('/content/drive/')
Mostrando as imagens do grupo
#img_grupo = plt.imread("/content/drive/My Drive/Colab Notebooks/FotosGrupo.png")
img_grupo = plt.imread('FotosGrupo.png')
altura, largura, camadas = img_grupo.shape
print("Resolução da imagem original: {} X {} PIXELS.".format(altura, largura) )
plt.imshow(img_grupo)
plt.xticks([]), plt.yticks([])
plt.show()
Resolução da imagem original: 1277 X 4312 PIXELS.
Versão P&B
img_grupo_PB = cv .cvtColor(img_grupo,cv.COLOR_BGR2GRAY)
plt.imshow(img_grupo_PB, cmap='gray')
plt.xticks([]), plt.yticks([])
plt.show()
Mostrando os avatares
#img_avatares = plt.imread("/content/drive/My Drive/Colab Notebooks/Avatares.jpg")
img_avatares = plt.imread('Avatares.jpg')
altura, largura, camadas = img_avatares.shape
print("Resolução da imagem original: {} X {} PIXELS.".format(altura, largura) )
plt.imshow(img_avatares)
plt.xticks([]), plt.yticks([])
plt.show()
Resolução da imagem original: 928 X 3384 PIXELS.
Versão P&B
img_avatares_PB = cv .cvtColor(img_avatares,cv.COLOR_BGR2GRAY)
plt.imshow(img_avatares_PB, cmap='gray')
plt.xticks([]), plt.yticks([])
plt.show()
Alterando as resoluções da imagens
img_grupo2 = cv.resize(img_grupo, None, fx=0.5, fy=0.5, interpolation = cv.INTER_CUBIC)
altura, largura, camadas = img_grupo2.shape
print( "Resolução da imagem alterada: {} X {} PIXELS.".format( altura, largura ) )
plt.imshow(img_grupo2)
plt.xticks([]), plt.yticks([])
plt.show()
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Resolução da imagem alterada: 638 X 2156 PIXELS.
img_grupo3 = cv.resize(img_grupo, None, fx=0.25, fy=0.25, interpolation = cv.INTER_CUBIC)
altura, largura, camadas = img_grupo3.shape
print( "Resolução da imagem alterada: {} X {} PIXELS.".format( altura, largura ) )
plt.imshow(img_grupo3)
plt.xticks([]), plt.yticks([])
plt.show()
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Resolução da imagem alterada: 319 X 1078 PIXELS.
img_avatares2 = cv.resize(img_avatares, None, fx=0.5, fy=0.5, interpolation = cv.INTER_CUBIC)
altura, largura, camadas = img_avatares2.shape
print( "Resolução da imagem alterada: {} X {} PIXELS.".format( altura, largura ) )
plt.imshow(img_avatares2)
plt.xticks([]), plt.yticks([])
plt.show()
Resolução da imagem alterada: 464 X 1692 PIXELS.
img_avatares3 = cv.resize(img_avatares, None, fx=0.25, fy=0.25, interpolation = cv.INTER_CUBIC)
altura, largura, camadas = img_avatares3.shape
print( "Resolução da imagem alterada: {} X {} PIXELS.".format( altura, largura ) )
plt.imshow(img_avatares3)
plt.xticks([]), plt.yticks([])
plt.show()
Resolução da imagem alterada: 232 X 846 PIXELS.
Vamos usar o HTML para exibir vídeos no Colab!
from IPython.display import HTML
from base64 import b64encode
video_path = "/content/drive/My Drive/Colab Notebooks/Video.mp4"
#video_path = "Video.mp4"
mp4 = open(video_path,'rb').read()
decoded_vid = "data:video/mp4;base64," + b64encode(mp4).decode()
HTML(f'<video width=720 controls><source src={decoded_vid} type="video/mp4"></video>')
--------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) <ipython-input-13-2d4398e02de0> in <module> 5 #video_path = "Video.mp4" 6 ----> 7 mp4 = open(video_path,'rb').read() 8 decoded_vid = "data:video/mp4;base64," + b64encode(mp4).decode() 9 HTML(f'<video width=720 controls><source src={decoded_vid} type="video/mp4"></video>') FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/My Drive/Colab Notebooks/Video.mp4'
Videos com alteração de resolução
HTML(f'<video width=360 controls><source src={decoded_vid} type="video/mp4"></video>')
HTML(f'<video width=180 controls><source src={decoded_vid} type="video/mp4"></video>')